-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adopting according to new readability and code style #553
Conversation
TBH I find this less readable than the original. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should double quote variable expansions.
Tip
Copy the script to a new file (eg: file.sh
), and run shellcheck file.sh
.
I guess there will be no consensus, but I'll point out the problems with reviewing the original:
Would it perhaps be better to write tests in a language other than a shell-script language? I think sh/bash (or at least its conventions) can make what should be readable code into difficult to read code. |
@adwk67 I understand and I don't want to judge on any of that. Not the neccesary experience. To me it's important to have the same style everywhere to avoid longish test interpretations and excess development work. I'm happy with both solutions, now I follow the discussion of stackabletech/superset-operator#533 where the discussion originate from, a few PR's have been done already. ( nothing we can't revert ) I'm also more than happy to facilitate a discussion or draft a decision. We need to find common ground on how to write test scripts and tests in general. I've discussed with @NickLarsenNZ briefly the possibility to solve stuff with |
To be more specific (and hopefully a little more helpful!), I found the original change (for airflow, I think) absolutely the right thing, as we had repeated cases. But with this one I find it harder to see what I am checking for. Wrapped lines are a pain, but in these two lines
it says to me: "identify a pod by name and rolegroup, look up the envvars and read the value for a named one". With the new version I find my eyes having to move back up the page to see what my variable-ized kubectl call was referring to. |
Yeah good point. The jumping back up and down (or rather, the consequence of abstracting) is a pain too. Thinking a little more about this, from the review perspective, I want to understand what the author is intending the assertions to be, then understand if that lines up with what is written. So perhaps commentary could help here too. The wrapping is still a pain for me (and in your example above, I couldn't read the right hand side because the github UI puts a big copy button over it (doesn't happen in review, just pointing it out here). Here is another go at spreading across multiple lines to reduce wrapping, without abstracting commands, and adding comments. # Get the first pod name via label lookup, stripping the pod/ prefix
POD=$(
kubectl -n "$NAMESPACE" get pod \
-l app.kubernetes.io/component=master,app.kubernetes.io/role-group=default \
-o name \
| head -n 1 \
| sed -e 's#pod/##'
)
# Assert that the pod contains 'MASTER' in the 'TEST_VAR_FROM_MASTER' env var
kubectl -n "$NAMESPACE" get pod "$POD" -o yaml \
| yq '.spec.containers[0].env[] | select (.name == "TEST_VAR_FROM_MASTER").value'
| grep 'MASTER' The comments might seem redundant, but take the following case which might show a copy/paste error that could be picked up in review: # Assert that the pod contains 'MASTER' in the 'TEST_VAR_FROM_MASTER' env var
kubectl -n "$NAMESPACE" get pod "$POD" -o yaml \
| yq '.spec.containers[0].env[] | select (.name == "TEST_VAR_FROM_MASTER").value'
| grep 'SECONDARY' "oops, it looks like we are lookup up the wrong thing, or is the comment wrong?" Long story short, is the example above any better for you @adwk67? |
That example is a big improvement, I'd say, and there may well still be cases where it makes more sense to extract specific things out into variables like your original proposal.
|
I agree with all points. Considering I caused this whole dilemma to surface, I'll check in with @Maleware and see where I can help to achieve those points in this PR, the come back to see if that resolves the readability issue your raised above. |
Small update while I'm editing things, I can definitely see how the existing style (before this PR) is ideal. It is just problematic during in the Github UI with the word wrapping during review. (could Github please add overflow to the split-pane reviews instead of wrapping?) So fixing it for review makes it worse for editing, and vice-versa. I will push up my edits anyway just so we can take a look (we can always revert them). |
This would be picked up by `shellcheck` in CI if the script wasn't inlined. We should consider moving test scripts out of yaml files.
According to [kuttl docs], scripts are executed via `sh -c`. The docs do not suggest if strict mode is enabled, so we should set it. There also doesn't seem to be a way to choose the shell (whithout calling a shell youself from within the script). Without strict mode on, only the final commands exist status is considered - meaning assertions before the last could fail and never be picked up. [kuttl docs]: https://kuttl.dev/docs/testing/steps.html#shell-scripts
It might seem trivial, but it can help reviewers quickly understand what the command line is for, and quickly assert whether that lines up with what the command line is actually doing.
We should test exact matches with grep. By default, `yq` will output strings with double quotes, so those should be removed with `-r` or `--unwrapScalar` for yq-go (the python yq which has the same options as jq can use `-r` or `--raw-output`). Note: I just leart about the `-w` option, which would remove the need for '^$'.
…l options into multiple args Instead of splitting by line-length, I am: - Splitting by pipe - Splitting by flag/option This is to make reviews simpler when using split panes (side-by-side).
I went to town on this one. You could argue that trivial cases (eg: `sed -e`) are ok. This is just for demonstration.
I have added a number of commits, each concerning a single thing. I have also added additional commit comments to give reasoning. As I mentioned earlier, if some/all of these commits are not tolerable (please consider both writing/maintenance as well as review perspectives), I can revert them. For what it is worth, here is the problem I had with the original change (stackabletech/superset-operator#533) that started this set of changes. It wasn't the changed line specifically, but rather the continued pattern of very long lines (which I admit are fine in my text editor) where the wrapping makes it really hard for me to review: |
I would agree with all of these. And thank you for taking the time to give this considerable thought! (and to @Maleware for going through all the tests to make things as consistent as possible). |
Also to note: in these commits there are still duplicate calls to |
@NickLarsenNZ Yeah I think it's morre readable without long variants. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - thanks!
LGTM for me too! Thanks for your work folks :) |
Description
As @NickLarsenNZ pointed out we could get better in code style and readability. This are suggested changes of him first used in stackabletech/superset-operator#533 and now being propagated through operators.
Definition of Done Checklist
Author
Reviewer
Acceptance